<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include  file="../../../base/base.jsp"  %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="edge" />
    <title> 汕头自来水微信服务系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="<c:url value="/resources/js/bootstrap/img/shantou.ico"/>" />
    <link href="<c:url value="/resources/js/bootstrap/css/twitter-bootstrap/bootstrap.css"/>" rel="stylesheet">
    <link href="<c:url value="/resources/js/bootstrap/css/social-jquery-ui-1.10.0.custom.css"/>" rel="stylesheet">
    <link href="<c:url value="/resources/js/bootstrap/css/social.css"/>" rel="stylesheet">
    <link href="<c:url value="/resources/js/bootstrap/css/social.plugins.css"/>" rel="stylesheet">
    <link href="<c:url value="/resources/js/bootstrap/css/font-awesome.css"/>" rel="stylesheet">
    <link href="<c:url value="/resources/js/bootstrap/css/social-coloredicons-buttons.css"/>" rel="stylesheet">
    <!--[if lt IE 9]>
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/js/bootstrap/css/social-jquery.ui.1.10.0.ie.css"/>"/>
    <![endif]-->
    <link href="<c:url value="/resources/js/bootstrap/css/demo.css"/>" rel="stylesheet">
    <link href="<c:url value="/resources/js/bootstrap/css/themes/social.theme-blue.css"/>" rel="stylesheet" id="theme">
    <!-- 本页调用样式 开始 -->
    <link href="<c:url value="/resources/js/cms/cms.css"/>" rel="stylesheet">
    
    
    
    <!-- jqgrid  The link to the CSS that the grid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="<c:url value="/resources/js/bootstrap/plugins/jquery.jqgrid/css/ui.jqgrid.css"/>" />
    <meta charset="utf-8" />
    <title>jqGrid Loading Data - Million Rows from a REST service</title>
    
    
    <!-- 本页调用样式 结束 -->
    <style>
        .wraper #main{ margin-top: 40px; }
    </style>
    <!--[if lt IE 9]>
    <script src="<c:url value="/resources/js/bootstrap/plugins/html5shiv.js"/>"></script>
    <![endif]-->
</head>

<body>
<!-- 外框架 开始 -->
<div class="wraper sidebar-full">
    <!-- 侧栏 -->
    <aside class="social-sidebar sidebar-full">
    <!-- 用户设置 -->
    <div class="user-settings">
       <jsp:include page="../../../base/cus/userSetting.jsp"/>
    </div>
    <!-- 内容 -->
    <div class="social-sidebar-content">
    <div class="scrollable">
    <!-- 用户信息 -->
    <div class="user"><img class="avatar" width="25" height="25" src="<c:url value="/resources/js/bootstrap/img/avatar.png"/>" alt="Julio Marquez"><span>${user.loginName }</span><i class="icon-user trigger-user-settings"></i></div>
    <div class="navigation-sidebar"><i class="switch-sidebar-icon icon-align-justify"></i></div>
    <!-- 搜索表单 -->
    <!--<div class="search-sidebar">
        <img src="assets/img/icons/stuttgart-icon-pack/32x32/search.png" alt="Search">
        <form class="search-sidebar-form">
            <input type="text" class="search-query input-block-level" placeholder="Search">
        </form>
    </div>-->
    <!-- 主菜单 开始 -->

	<section class="menu">
    <jsp:include page="../../../base/cus/menu.jsp"/>
    </section>
    <!-- 主菜单 结束 -->
    </div>
    </div>
    </aside>
    <!-- 页头-->
    <header>
    <!-- 导航 -->
        <nav class="navbar navbar-fixed-top social-navbar social-sm">
            <jsp:include page="../../../base/cus/head.jsp"/>
        </nav>
    </header>

    <!-- 主体 -->
    <div id="main">
    <div class="container-fluid">
        <!--主体内容-->
        <h2 class="title_class">资源管理</h2>
        <div class="list_btn_div_class">
        <input type="button" id="addRecord" class="btn btn-default"  onclick="location='${pageContext.request.contextPath}/cus/sresource_toAdd.do?typeCode=resourceType'" value="新增">
         <input type="button" id="editRecord" class="btn btn-default"  onclick="updateRecord()" value="修改"> 
         <input type="button" id="delRecord" class="btn btn-default"  onclick="delRecord()" value="删除">
         <input type="button" id="viewRecord" class="btn btn-default"  onclick="viewRecord()" value="查看">
         </div>
        <table id="treegrid"></table>
        <div id="paddtree"></div>
    </div>

	<!-- 页脚开始 -->
    <footer id="footer">
        <jsp:include page="../../../base/cus/foot.jsp"/>
    </footer>
    <!-- 页脚结束 -->
    </div>
</div>
<script src="<c:url value="/resources/js/bootstrap/plugins/jquery/jquery.js"/>"></script>
<script src="<c:url value="/resources/js/bootstrap/plugins/twitter-bootstrap/bootstrap.js"/>"></script>
<script src="<c:url value="/resources/js/bootstrap/plugins/jquery.slimscroll/jquery.slimscroll.min.js"/>"></script>
<script src="<c:url value="/resources/js/bootstrap/js/extents.js"/>"></script>
<script src="<c:url value="/resources/js/bootstrap/js/sidebar.js"/>"></script>

<script type="text/javascript"  src="<c:url value="/resources/js/bootstrap/plugins/bootstrap.bootbox/4.4.0/bootbox.js"/>"></script>

<!-- This is the Javascript file of jqGrid -->   
<script type="text/ecmascript" src="<c:url value="/resources/js/bootstrap/plugins/jquery.jqgrid/js/jquery.jqGrid.min.js"/>"></script>
<!-- This is the localization file of the grid controlling messages, labels, etc.
<!-- We support more than 40 localizations -->
<script type="text/ecmascript" src="<c:url value="/resources/js/bootstrap/plugins/jquery.jqgrid/js/i18n/grid.locale-cn.js"/>"></script>

<!-- 本页调用JS 开始 -->
<script>
    $(function() {
        SideBar.init({
            shortenOnClickOutside: false
        });
    });

    $(document).ready(function () {
    	
	    jQuery("#treegrid").jqGrid({
	       	url: '${pageContext.request.contextPath}/cus/sresource_list_json.do',
	       	mtype: "GET",
            contentType: "application/json",
            datatype: "json",
            colModel:[
      		       	{ label: '选择', name: 'id', key: true,hidden:true,width: 60, align:'center', formatter:'checkbox' , formatoptions:{disabled:false}},
      	     		{ label: '菜单名', name: 'resName', width: 300},
      	     		{ label: '资源类型', name: 'resType.dicName', width: 150},
      	     		{ label: '权限链接', name: 'authUrl', width: 150 },
      	            { label: '资源代码', name: 'resCode', width: 150  },
      	            { label: '请求链接', name: 'reqUrl', width: 150  },
      	            { label: '是否显示', name: 'isShowMenu', width: 60, align:'center', formatter:'checkbox', editoptions:{value:'1:0'}, formatoptions:{disabled:true}}
      	    ],
	    	height:'auto',
	    	pager : "false",
	        treeGrid: true,
	    	ExpandColumn : 'resName',
	    	treeGridModel: 'adjacency',
	    	multiselect: true,
	    	onSelectRow: function (rowid, status) {
				selId = rowid;
			}
	    });
	    
	    jQuery("#addtree").jqGrid('navGrid',"#paddtree");
	    
    });
        
    
    //修改操作
    function updateRecord(){
    	var id = $("#treegrid").jqGrid("getGridParam", "selrow");
    	if(id==null || id==""){
    		bootbox.alert("请选择需要修改记录！");
    	}else {
    		
    		$.get(
           			"${pageContext.request.contextPath}/cus/sresource_checkResourceId.do?id="+id,
           			function(msg){
           				if(msg.result==true){
           					location.href='${pageContext.request.contextPath}/cus/sresource_toUpdate.do?id='+id;
       		            }else{
       		            	bootbox.alert(msg.warnMsg); 
       		            	return false;
       		            }
    	            	
           			}
        		); 
    		
    		
    	}
    	
    }
    
    function viewRecord(){
    	
    	var id = $("#treegrid").jqGrid("getGridParam", "selrow");
    	if(id==null || id==""){
    		bootbox.alert("请选择需要修改记录！");
    	}else {
    		
    		$.get(
           			"${pageContext.request.contextPath}/cus/sresource_checkResourceId.do?id="+id,
           			function(msg){
           				if(msg.result==true){
           					location.href='${pageContext.request.contextPath}/cus/sresource_toView.do?id='+id;
       		            }else{
       		            	bootbox.alert(msg.warnMsg); 
       		            	return false;
       		            }
    	            	
           			}
        		); 
    		
    		
    	}
    	
    }
    
    
    function delRecord(){
    	
    	var id = $("#treegrid").jqGrid("getGridParam", "selrow");
    	if(id==null || id==""){
    		bootbox.alert("请选择需要删除记录！");
    	}else{
    		bootbox.confirm('确定需要删除吗？',
        		    function(result){
    			
    			if(result==true){  //执行删除操作
    		    	$.post(
    	           			"${pageContext.request.contextPath}/cus/sresource_delete.do",
    	           			{"id":id,"${_csrf.parameterName}":"${_csrf.token}"},
    	           			function(msg){
    	           				if(msg.result==true){
    	           					bootbox.alert(msg.warnMsg, function(){
    	    						    	window.location.href='${pageContext.request.contextPath}/cus/sresource_list.do';
    	    						    }); 
    	       		            }else{
    	       		            	bootbox.alert(msg.warnMsg); 
    	       		            	return false;
    	       		            }
    	    	            	
    	           			}
    	        		); 
    			}
    			
    		});
    	}
    }
    
   </script>
<!-- 本页调用JS 结束 -->
</body>

</html>